package com.ncloud.product.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import com.ncloud.product.entity.Product;

@Mapper
public interface ProductMapper{

	@Select("select * from bs_p_product where prod_state='1'")
	@Results({@Result(column="prod_id",property="prodId"),@Result(column="prod_name",property="prodName"),
		@Result(column="prod_State",property="prodState"),@Result(column="eff_mode",property="effMode"),
		@Result(column="prod_type",property="prodType"),
		@Result(column="billing_cycle",property="billingCycle"),@Result(column="cycle_unit",property="cycleUnit"),
		@Result(column="create_date",property="createDate"),@Result(column="create_user",property="createUser"),
		@Result(column="update_date",property="updateDate"),@Result(column="update_user",property="updateUser"),
		@Result(column="remarks",property="remarks"),@Result(column="prod_explain",property="prodExplain")})
	List<Product> getAllProducts();
	
	@Select("select * from bs_p_product where prod_id = #{prodId} and prod_state='1'")
	@Results({@Result(column="prod_id",property="prodId"),@Result(column="prod_name",property="prodName"),
		@Result(column="prod_type",property="prodType"),
		@Result(column="prod_State",property="prodState"),@Result(column="eff_mode",property="effMode"),
		@Result(column="billing_cycle",property="billingCycle"),@Result(column="cycle_unit",property="cycleUnit"),
		@Result(column="create_date",property="createDate"),@Result(column="create_user",property="createUser"),
		@Result(column="update_date",property="updateDate"),@Result(column="update_user",property="updateUser"),
		@Result(column="remarks",property="remarks"),@Result(column="prod_explain",property="prodExplain")})
	Product getProdInfo(@Param("prodId")Long prodId);

	@Select("select distinct a.* from bs_p_product a ,bs_p_discnt_release b "
			+ " where a.prod_id = b.prod_id and a.prod_state ='1' "
			+ " and b.chnl_id = #{chnlId} and NOW() BETWEEN b.eff_date and b.exp_date")
	@Results({@Result(column="prod_id",property="prodId"),@Result(column="prod_name",property="prodName"),
		@Result(column="prod_type",property="prodType"),
		@Result(column="prod_State",property="prodState"),@Result(column="eff_mode",property="effMode"),
		@Result(column="billing_cycle",property="billingCycle"),@Result(column="cycle_unit",property="cycleUnit"),
		@Result(column="create_date",property="createDate"),@Result(column="create_user",property="createUser"),
		@Result(column="update_date",property="updateDate"),@Result(column="update_user",property="updateUser"),
		@Result(column="remarks",property="remarks"),@Result(column="prod_explain",property="prodExplain")})
	List<Product> getProdList(Long chnlId);

}
